/*
	Pinkie's Balloon Fight
	Copyright (C) 2012  dancinninja (dancinninjac@gmail.com)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "Enemy.h"
#include <ctime>

// The minimum amount of time between actions
static const u32 ENEMY_BASE_ACTION_TIME = 1000;
//----------------------------------------
// Default Constructor
//----------------------------------------

Enemy::Enemy(){
	// Most enemies start with only one life
	lives = 1;
	width = 30;
	height = 30;
	// Note: the "400" will change for each type of enemy
	timeToChangeAction = std::rand() % 400 + ENEMY_BASE_ACTION_TIME;
	changeActionTimer = timeToChangeAction;
}

void Enemy::Update(){

	// Let's apply our AI!!
	changeActionTimer--;
	if(changeActionTimer < 1){
		changeActionTimer = timeToChangeAction;
		ChangeAction();
	}


	// ---------- Apply Gravity---------------------------
	if(yAccel > - TERMINAL_VELOCITY - GRAVITY_ACCELERATION){ 
		yAccel -= GRAVITY_ACCELERATION;
	}	
	
	// Regular update
	LiveObject::Update();
}

void Enemy::ChangeAction(){

	// This is a pretty big cheat, and not AI at all
	int randNum = std::rand() & 10;
	float randNumFloat = float(randNum) / 100;
	if(randNum & 2){
		xAccel += randNumFloat;
	}else{
		xAccel -= randNumFloat;
	}
	// TODO: this doesn't have to be a jump!
	Jump();
}